#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    priority_queue<int, vector<int>, greater<int>> pq;
    vector<int> vec;
    for(int i = 1; i <= n; i++) {
        if(i - a[i] > 0) {
            vec.push_back(i);
            pq.push(a[i]);
        }
    }
    int ans = 0;
    for(auto x : vec) {
        while(pq.size() && pq.top() <= x) pq.pop();
        ans += pq.size();
    }
    cout << ans << endl;
}

signed main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}